<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=\, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    html,
    body {
      height: 100%;
    }

    body {
      display: flex;
      justify-content: center;
      align-items: center;
    }

    div {
      width: 400px;
    }

    input {
      height: 40px;
      width: 400px;
    }

    ul,
    li {
      list-style: none;
      padding: 0;
    }
  </style>
</head>

<body>
  <div>
    <input type="text" placeholder="请输入你想搜索的内容">
    <ul style="display: none;">
    </ul>
  </div>
  <script>
    let Data = null
    function myFun(data) {
      Data = data
    }

    const input = document.querySelector('input')

    input.addEventListener('input', function () {
      const timeId = setTimeout(() => {
        if (timeId) clearTimeout(timeId)
        document.querySelector('ul').style.display = 'block'
        const myScript = document.createElement('script')
        myScript.src = `https://suggest.taobao.com/sug?q=${this.value}&callback=myFun`
        document.body.appendChild(myScript)
        document.body.removeChild((myScript))
        if (!Data) return
        const listStr = Data.result.map(item => `
      <li>${item[0]}</li>
      `).join('')
        console.log(listStr)
        document.querySelector('ul').innerHTML = listStr
        if (!input.value) document.querySelector('ul').style.display = 'none'
      }, 500)
    })


  </script>
</body>

</html>